package com.tlias.mapper;

import com.tlias.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/*
* 员工管理
* */
@Mapper
public interface EmpMapper {

    /*
    * 分页查询
    * */
    //@Select("select * from emp limit #{start},#{pageSize}")
    //List<Emp> page(Integer start, Integer pageSize);

    /*
    * 统计数量
    * */
    //@Select("select count(*) from emp")
    //Long count();

    /*
    * 查询员工数量
    * */
    //@Select("select * from emp")
    List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);

    /*
     * 批量删除
     * */
    void delete(List<Integer> ids);

    /*
     * 新增员工
     * */
    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /*
     * 根据ID查询员工
     * */
    @Select("select * from emp where id = #{id}")
    Emp getById(Integer id);

    /*
     * 更改员工数据
     * */
    void update(Emp emp);

    /*
     * 用户登录
     * */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectByIdAndUserName(Emp emp);

    /*
    * 根据部门id删除该部门下的员工
    * */
    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
